//
//  ModifypasswordViewController.m
//  Manage
//
//  Created by 杨康 on 2017/11/6.
//  Copyright © 2017年 杨康. All rights reserved.
//

#import "ModifypasswordViewController.h"

@interface ModifypasswordViewController ()
{
    YKTextField *_oldpwTF;
    YKTextField *_newpwTF;
    YKTextField *_newpwTF2;
}
@end

@implementation ModifypasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"修改密码";
    
    
    //原密码
    YKTextField *oldpwTF=[SingLeton myTextFieldsecure:YES andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入原密码" andLeftImage:nil RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
    }];
    _oldpwTF=oldpwTF;
    [self.view addSubview:oldpwTF];
    [oldpwTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30+TOP_HEIGHT);
        make.left.mas_equalTo(35);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-70, 44));
    }];
    
    //新密码
    YKTextField *newpwTF=[SingLeton myTextFieldsecure:YES andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请输入新密码" andLeftImage:nil RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
    }];
    _newpwTF=newpwTF;
    [self.view addSubview:newpwTF];
    [newpwTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(oldpwTF.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(35);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-70, 44));
    }];
    
    
    
    
    //再次密码
    YKTextField *newpwTF2=[SingLeton myTextFieldsecure:YES andkeyboardType:UIKeyboardTypeDefault andplaceholder:@"请再次输入新密码" andLeftImage:nil RequestSuccess:^(YKTextField *textField, NSRange range, NSString *string) {
    }];
    _newpwTF2=newpwTF2;
    [self.view addSubview:newpwTF2];
    [newpwTF2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(newpwTF.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(35);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-70, 44));
    }];
    
    
    //确定按钮
    UIButton  *confirmButton=[SingLeton endButton:[UIColor colorQ] andTitle:@"确定" RequestSuccess:^(UIButton *btn) {
        
        
        if ([_newpwTF.text isEqualToString:_newpwTF2.text]) {
            NSString *URLString = @"/axq/admin/password/change";
            NSDictionary *parameters = @{@"oldpassword": _oldpwTF.text, @"password": _newpwTF.text};
            [NetworkPath requestWithMethod:0 andURLString:URLString andParameters:parameters RequestSuccess:^(NSURLResponse *response, id responseObject) {
                NSString *code = responseObject[@"code"];
                if([code isEqualToString:@"10008"]){
                    NSString *str=@"密码修改成功";
                    
                    [self.view makeToast:str];
                }
                else
                {
                    NSString *str=responseObject[@"msg"];
                    
                    [self.view makeToast:str];
                }
                
            } RequestFailed:^(NSError *error) {
                
            }];
        }else
        {
            [self.view makeToast:@"两次输入新密码不一样，请检查后重新输入"];
        }
        
        
        
    }];
    [self.view addSubview:confirmButton];
    [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(newpwTF2.mas_bottom).mas_offset(20);
        make.left.mas_equalTo(newpwTF2);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-70, 44));
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
